import type {
    AttributeRenderer,
    BaseTextAttributes,
    DeltaInsert,
    VEditor,
} from '@notes/virgo';
import { baseTextAttributes } from '@notes/virgo';
import { z, type ZodTypeDef } from 'zod';

export const affineTextAttributes = baseTextAttributes.extend({
    reference: z
        .object({
            type: z.enum(['Subpage', 'LinkedPage']),
            pageId: z.string(),
        })
        .optional(),
    background: z.string().optional().catch(undefined),
});

export type AffineTextAttributes = z.infer<typeof affineTextAttributes>;

export type AffineDeltaInsert = DeltaInsert<AffineTextAttributes>;

export type AffineVEditor = VEditor<AffineTextAttributes>;

export type AffineTextSchema<
    TextAttributes extends BaseTextAttributes = AffineTextAttributes,
> = {
    attributesSchema: z.ZodSchema<TextAttributes, ZodTypeDef, unknown>;
    textRenderer: () => AttributeRenderer<TextAttributes>;
};
